/* 
 * File:        SpamEquationsApplication2.cpp
 * Author:      Cody TV Weber
 * Date:        March 26, 2014, 11:27 PM
 * Description: This file contains some key equations needed to determine 
 *              whether or not an email is spam or ham.
 */

#include "./mathematicalFunctions.h"

/*
 * double extremeProbabilityValue(double probability) - 
 *          Takes a word's probability built from the SpamIndicator as a 
 *          parameter and indicates how extreme the probability is from the 
 *          center of the statistical bell curve.  The indicator uses .5 to 
 *          indicate value of the how extreme the word is.
 */
double extremeProbabilityValue(double probability) {
    double mediumValue = .5;
    double result = (probability - mediumValue); // Creates an indication number (could possibly be negative).
    result = absoluteValue(result); //  Taking absolute value.

    return result; // Returning only a positive extreme probability value.  (Expected result range: 0.0 to 0.5)
}

/*
 * double spamFilterIndicatorValueEquation(int outliers[]) -
 *          Uses up to 15 outlier words to create an indication value used to
 *          compare with the User's specified cutoff value for indicating if
 *          an email is ham or spam.
 */
double spamFilterIndicatorValueEquation(array<double>^ outliers, int numberOfOutliers) {
    double indicatorValue = 0.0;
    double A = 0.0, B = 0.0, C = 0.0;
    array<double>^ P = gcnew array<double>(numberOfOutliers);

    //  Calculating the Numerator.
    A = iterativeProduct(outliers,numberOfOutliers);
    
    //  Calculating the first-half of the denominator.
    for(int i = 0; i < numberOfOutliers; i++){
        P[i] = (1 - outliers[i]);
    }
    B = iterativeProduct(P,numberOfOutliers);
    
    //  Calculating the second-half of the denominator.
    C = iterativeProduct(outliers,numberOfOutliers);
    
    indicatorValue = (A / (B + C)); //  Final Probability equation.

    return indicatorValue;
}